Using Task-Specific Storage
Task-specific storage is useful for storing small pieces of data, such as pointers to task-specific information. For example, if you create several identical tasks, each of which requires some unique data, you can store that data as task-specific storage. Task-specific storage locations are cross-referenced by an index value and the task ID, so the same code can easily refer to "per-instance" variables. Each such storage location holds a 32-bit value.
Task-specific storage is automatically allocated when a task is created; the amount is fixed and cannot change for the life of the task. To access the task-specific storage, you call the function MPAllocateTaskStorageIndex
. Doing so returns an index number which references a storage location in each available task in the process. Subsequent calls to MPAllocateTaskStorageIndex
return new task index values to access more of the task-specific storage. Note that, aside from the fact that each index value is unique, you should not assume anything about the actual values of the index. For example, you cannot assume that successive calls to MPAllocateTaskStorageIndex
will monotonically increase the index value.
Since the amount of task-specific storage is fixed, you may use up the available storage (and corresponding index values) if you make many MPAllocateTaskStorageIndex
calls. In such cases, further calls to MPAllocateTaskStorageIndex
return an error indicating insufficient resources.
You call MPSetTaskStorageValue
and MPGetTaskStorageValue
to set and retrieve the storage data. After you are finished using the storage locations, you must call MPDeallocateTaskStorageIndex
to free the index.
© 1999 Apple Computer, Inc. – (Last Updated 17 Nov 99)